package com.school.zhaoban.controller;


import com.school.zhaoban.pojo.College;
import com.school.zhaoban.response.CommonResponse;
import com.school.zhaoban.service.CollegeService;
import com.school.zhaoban.utils.UserLoginToken;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 又菜又爱玩
 * @since 2022-02-23
 */

@Slf4j
@RestController
@RequestMapping("/college")
public class CollegeController {



    @Autowired
    private CollegeService collegeService;

    @UserLoginToken
    @GetMapping("/getCollegeList")
    public List<College> findCollegeList(){
        log.debug("=====>测试日志debug级别打印<====");
        log.info("=====>测试日志info级别打印<=====");
        log.error("=====>测试日志error级别打印<====");
        log.warn("=====>测试日志warn级别打印<=====");

        return collegeService.findAll();
    }



    @PostMapping("/addCollege")
    public CommonResponse addCollege(@RequestBody @Valid College college) throws Exception{
        int i = collegeService.saveCollege(college);
        log.info("addCollege:" + college);
        if (i > 0){
            return CommonResponse.ok("添加成功");
        } else {
            return CommonResponse.fail(500, "添加失败");
        }
    }


    @PostMapping("/updateCollege")
    public CommonResponse updateCollege(@RequestBody @Valid College college) throws Exception{
        int i = collegeService.updateByID(college);
        if (i > 0){
            return CommonResponse.ok("更新成功");
        } else {
            return CommonResponse.fail(500, "添加失败");
        }
    }










}

